#include <iostream>
#include <queue>
#include <type_traits>
using namespace std;

typedef struct ListNode
{
    int val;
    struct ListNode* next;
}ListNode;

typedef struct Queue
{
    ListNode* phead;
    ListNode* list;
}Queue;

void QueueInit(Queue* q)
{
    q->list = q->phead = NULL;
}

void QueuePushBack(Queue* q, int n)
{
    ListNode* newnode = (ListNode*)malloc(sizeof(ListNode));
    newnode->next = q->phead;
    newnode->val = n;
    if (q->phead == NULL)
    {
        q->phead = q->list = newnode;
    }
    else
    {
        q->list->next = newnode;
        q->list = q->list->next;
    }
}

int main() {
    int man, num;
    cin >> man;
    cin >> num;
    Queue q;
    QueueInit(&q);
    for (int i = 1; i <= man; i++)
    {
        QueuePushBack(&q, i);
    }
    int size = 0;
    ListNode* l1 = q.list;
    ListNode* l2 = q.phead;
    ListNode* l3 = q.phead->next;
    while (man != 1)
    {
        size++;
        if (size == num)
        {
            size = 0;
            free(l2);
            l1->next = l3;
            l3 = l3->next;
            l2 = l1->next;
            man--;
        }
        else
        {
            l1 = l2;
            l2 = l3;
            l3 = l3->next;
        }
    }
    cout << l2->val << endl;
    free(l2);
    q.list = q.phead = NULL;
}

struct TreeNode {
    int val;
    struct TreeNode* left;
    struct TreeNode* right;
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
};

class Solution {
public:
    int ret = 0;
    int sumRight(TreeNode* root)
    {
        if (root == NULL)
        {
            return 0;
        }
        if (root->left == NULL && root->right == NULL)
        {
            return 0;
        }
        return sumLeft(root->left) + sumRight(root->right);
    }

    int sumLeft(TreeNode* root)
    {
        if (root == NULL)
        {
            return 0;
        }
        if (root->left == NULL && root->right == NULL)
        {
            return root->val;
        }
        return sumLeft(root->left) + sumRight(root->right);
    }

    int sumOfLeftLeaves(TreeNode* root) {
        // write code here
        if (root == NULL)
        {
            return 0;
        }
        return sumLeft(root->left) + sumRight(root->right);
    }
};